# wget https://huggingface.co/datasets/OpenDriveLab/OpenScene/resolve/main/openscene-v1.1/openscene_metadata_trainval.tgz
# tar -xzf openscene_metadata_trainval.tgz
# rm openscene_metadata_trainval.tgz
# mv openscene-v1.1/meta_datas trainval_navsim_logs
# rm -r openscene-v1.1

# mkdir -p trainval_sensor_blobs/trainval
# for split in {1..32}; do
#     wget https://huggingface.co/datasets/OpenDriveLab/OpenScene/resolve/main/navsim/navtrain_current_${split}.tgz
#     echo "Extracting file navtrain_current_${split}.tgz"
#     tar -xzf navtrain_current_${split}.tgz
#     rm navtrain_current_${split}.tgz

#     rsync -rv navtrain_current_${split}/* trainval_sensor_blobs/trainval
#     rm -r navtrain_current_${split}
# done

# for split in {1..32}; do
#     wget https://huggingface.co/datasets/OpenDriveLab/OpenScene/resolve/main/navsim/navtrain_history_${split}.tgz
#     echo "Extracting file navtrain_history_${split}.tgz"
#     tar -xzf navtrain_history_${split}.tgz
#     rm navtrain_history_${split}.tgz

#     rsync -rv navtrain_history_${split}/* trainval_sensor_blobs/trainval
#     rm -r navtrain_history_${split}
# done

# ====================================

# export HF_ENDPOINT=https://hf-mirror.com

# 下载 metadata 文件
huggingface-cli download \
  --resume-download \
  --repo-type dataset \
  OpenDriveLab/OpenScene \
  openscene-v1.1/openscene_metadata_trainval.tgz \
  --local-dir openscene_metadata \
  --local-dir-use-symlinks False

# 解压 metadata 并整理目录
tar -xzf openscene_metadata/openscene_metadata_trainval.tgz -C openscene_metadata
rm openscene_metadata/openscene_metadata_trainval.tgz
mv openscene_metadata/meta_datas trainval_navsim_logs
rm -r openscene_metadata/openscene-v1.1
rmdir openscene_metadata

# 创建目标目录
mkdir -p trainval_sensor_blobs/trainval

# 下载并处理 navtrain_current_*.tgz 文件
# for split in {1..32}; do
for split in {1..2}; do
  huggingface-cli download \
    --resume-download \
    --repo-type dataset \
    OpenDriveLab/OpenScene \
    navsim/navtrain_current_${split}.tgz \
    --local-dir navtrain_current_${split} \
    --local-dir-use-symlinks False

  # 解压并合并文件
  tar -xzf navtrain_current_${split}/navtrain_current_${split}.tgz -C navtrain_current_${split}
  rsync -rv navtrain_current_${split}/* trainval_sensor_blobs/trainval
  rm -rf navtrain_current_${split}
done

# 下载并处理 navtrain_history_*.tgz 文件
for split in {1..2}; do
  huggingface-cli download \
    --resume-download \
    --repo-type dataset \
    OpenDriveLab/OpenScene \
    navsim/navtrain_history_${split}.tgz \
    --local-dir navtrain_history_${split} \
    --local-dir-use-symlinks False

  # 解压并合并文件
  tar -xzf navtrain_history_${split}/navtrain_history_${split}.tgz -C navtrain_history_${split}
  rsync -rv navtrain_history_${split}/* trainval_sensor_blobs/trainval
  rm -rf navtrain_history_${split}
done
